<?php
/*
  Above this we will hang on with the session and we will manage the sites and its languages through the object server.
  This code is before the sites so it is common for all of them.
  It contains all general classes declarations so they are needed when user object is recovered frm the session
  because user object can contain any of these other classes (object definitions)
 */
 

session_start();
// Predefined standard classes
include("includes/classes/standard.php");

# Sites definition
require('includes/sites/config.php');

#Multisite support
include("includes/classes/node.php");
include('includes/classes/sites.php');

#We have to load the classes of the objets that could be in the session
#because unserialize will produce an error if the class it is not defined
require('includes/classes/user.php');
include('includes/classes/order.php');
include('includes/classes/address.php');
include('includes/classes/item.php');
include('includes/classes/category.php'); //Maybe not needed now
include('includes/classes/cart.php');
include('includes/classes/location.php');
//This is for saving the $_GET["domain"] in the httpxmlrequest but we need a way to update to server_name an unset $_GET
if (!isset($_SESSION["ser_server"])){
	//We create the server object. Server is in charge or managing sites.
	$server= new server();
	#We load the sites to the server
	$server->load_sites();
	#We set the actual site
	if (isset($_GET["domain"]) && MODE=="test") $server->set_default($_GET["domain"]);
	else $server->set_default($_SERVER['SERVER_NAME']);
}
else {
	$server=unserialize($_SESSION["ser_server"]);
		if (isset($_GET["domain"]) && MODE=="test") {
			$server->set_default($_GET["domain"]);//print_r($server->my_site);
		}
		// we need a way to find out if the server_n set a server property when there is no serer coincidence and server is to first site
		elseif (!$server->my_site[0]->is_host($_SERVER['SERVER_NAME']) && !MODE=="test") {
			$server->set_default($_SERVER['SERVER_NAME']);
		}
}
//We load the site configuration and create a conection to the database
$server->init();

$_SESSION["ser_server"]=serialize($server);

/*
 * This part manage the site printing. There are two posibilites:
 * 1) We want to download the entire site. It will show every part of the page.
 * 2) We want to download just a section of the page.
 */

if (isset($_GET[ "section" ])) {
	include($server->get_path_name($_GET[ "section" ] . '.php'));
	/*
	echo "hola";
	echo "Path name ". $server->get_path_name($_GET[ "section" ] . '.php');
	print_r($server->my_site);*/
}
 else {
	include($server->get_path_name('index.php'));
}
?>
